#include <cmath>
#include "vector.h"

vector vector::operator+(vector const & oth) const
{
    return vector(x + oth.x, y + oth.y);
}

vector vector::operator+(float const op) const
{
    return vector(x + op, y + op);
}

vector vector::operator-(vector const & oth) const
{
    return vector(x - oth.x, y - oth.y);
}

vector vector::operator*(float const op) const
{
    return vector(op * x, op * y);
}

vector vector::operator/(float const op) const
{
    return *this * (1.0 / op);
}

vector vector::operator=(vector const & oth)
{
    x = oth.x;
    y = oth.y;
    return *this;
}

std::ostream & operator<<(std::ostream & os, vector const & vector)
{
    os << '(' << vector.x << ", " << vector.y << ')';
    return os;
}

float vector::norm() const { return std::sqrt(x * x + y * y); }

float vector::distance(vector const & oth) const
{
    vector sub = *this - oth;
    return sub.norm();
}

void vector::set(float const x, float const y) { this->x = x; this->y = y; }
